<?php

require_once("../util/db.php");

$username = $_POST['username'];
$password = $_POST['password1'];

$sql = "SELECT * FROM user WHERE username ='$username'";

$retval = mysqli_query($conn, $sql);
if (!$retval) {
    die('无法读取数据:' . mysqli_error($conn));
}
$rows = mysqli_fetch_all($retval);

if (count($rows) > 0) {
    header('Location: ../pages/Neasteregest.html?flag=204&msg=用户已存在');
} else {
    $sql = "INSERT  INTO user (username,password) VALUES ('$username','$password')";
    $retval = mysqli_query($conn, $sql);
    // $s = mysqli_fetch_all($retval);
    if ($retval) {
        header('Location: ../pages/Neastelogin.html?flag=200&msg=注册成功');
    } else {
        header("Location: ../pages/Neasteregest.html?flag=204&msg=注册失败");
    }
}

mysqli_free_result($retval);
mysqli_close($conn);
